<?php

class Course{
    var $courseid;
    var $coursename;
    var $coursecredit;

	function setAll($courseid,$coursename,$coursecredit){
		$this->courseid = $courseid;
		$this->coursename = $coursename;
		$this->coursecredit = $coursecredit;
	}
    
    function addCourse($courseid,$coursename,$coursecredit,$trnpid,$coursesecond,$reltype){
        $sql = "INSERT INTO `course` (COURSE_ID,COURSE_NAME,COURSE_CREDIT) VALUES ('".$courseid."','".$coursename."',".$coursecredit.")";
        $sql2 = "INSERT INTO `courserelationship` (TRNP_ID,COURSE_ID,SECOND_COURSE_ID,COURSE_REL_TYPE) VALUES ('".$trnpid."','".$courseid."','".$coursesecond."','".$reltype."')";
        mysql_query($sql);
        mysql_query($sql2);
    }
    function editCourse($courseid,$coursename,$coursecredit,$trnpid,$coursesecond,$reltype,$relid){
        $sql = "UPDATE course SET COURSE_NAME = '".$coursename."',COURSE_CREDIT=".$coursecredit." WHERE COURSE_ID = '".$courseid."'";
        $sql2 = "UPDATE courserelationship SET TRNP_ID = '".$trnpid."',SECOND_COURSE_ID='".$coursesecond."',COURSE_REL_TYPE='".$reltype."' WHERE COURSE_REL_ID = ".$relid;
        
        mysql_query($sql);
        mysql_query($sql2);
    }
    function deleteCourse($courseid){
        $sql = "DELETE FROM course WHERE COURSE_ID='".$courseid."'";
        $sql2 = "DELETE FROM courserelationship WHERE COURSE_ID='".$courseid."'";
        $sql3 = "DELETE FROM courseregistration WHERE COURSE_ID='".$courseid."'";
       
        mysql_query($sql3);
        mysql_query($sql2);
        mysql_query($sql);
    }
}



?>